/* Susan(tm) Java Version
   by Thomas Lochmatter, Brig-Glis, Switzerland
   and Patrick Bizeau, Brig-Glis, Switzerland    */
   
package laWa;
import java.io.*;
import java.awt.*;

// Some options. A part of them can be changed via the SusanNewGameDialog or
// the SusanNetworkDialog. Others are initialized to a fix value.
public class SusanOptions {

  // ######################### INSTANCE VARIABLES
  public int playmode=0;
  public static final int playmode_pl=0;
  public static final int playmode_pc=1;
  public static final int playmode_net=2;
  public static final int playmode_analize=3;
  public int begin=0;
  public static final int begin_you=0;
  public static final int begin_opp=1;
  public static final int begin_random=2;
  public String player1;
  public String player2;
  public String backgroundimage;
  public Color backgroundcolor;
  public Color boardcolor;
  public Color boardshadowcolor;
  public Color boardbordercolor;
  public Color player1color;
  public Color player2color;
  public Color player1movecolor;
  public Color player2movecolor;
  public Color fortresscolor;
  public Color victimcolor;
  public Color loosercolor;
  public Color lostcolor;
  public Color markcolor;
  public Color arrowcolor;
  public Color arrowbordercolor;
  public boolean boardshadow=false;
  public int shape=0; // 0=circle, other values use shapepolygon
  public static final int shape_circle=0;
  public static final int shape_hexagon=1;
  public static final int shape_star=2;
  public static final int shape_triangle=3;
  public Polygon shapepolygon;
  public boolean showFortress=false;
  public boolean showVictims=false;
  public boolean showLoosers=false;
  public String nethost;
  public int netport;

  // ######################### CONSTRUCTOR
  public SusanOptions() {
    player1="Player 1";
    player2="Player 2";
    nethost="localhost";
    netport=27133;
    backgroundimage="laWa/wet.lbg";
    backgroundcolor=new Color(192,192,127);
    boardcolor=new Color(255,255,255);
    boardshadowcolor=new Color(0,0,0,32);
    boardbordercolor=new Color(127,127,127);
    player1color=new Color(192,0,0);
    player1movecolor=new Color(255,192,192);
    player2color=new Color(0,0,192);
    player2movecolor=new Color(192,192,255);
    fortresscolor=new Color(255,255,192);
    victimcolor=new Color(192,255,192);
    loosercolor=new Color(255,192,192);
    lostcolor=new Color(64,64,64);
    markcolor=new Color(192,192,192);
    arrowcolor=new Color(64,0,0);
    arrowbordercolor=new Color(0,0,0);
    loadOptions();
  }

  // ######################### VARIOUS METHODS

  // Set the polygon shape
  public void setShape(int shape) {
    this.shape=shape;
    if (shape==shape_circle) {
      shapepolygon=null;
      return;
    }
    shapepolygon=new Polygon();
    if (shape==shape_hexagon) {
      shapepolygon.addPoint(0,100);
      shapepolygon.addPoint(90,50);
      shapepolygon.addPoint(90,-50);
      shapepolygon.addPoint(0,-100);
      shapepolygon.addPoint(-90,-50);
      shapepolygon.addPoint(-90,50);
    } else if (shape==shape_triangle) {
      shapepolygon.addPoint(0,-100);
      shapepolygon.addPoint(88,67);
      shapepolygon.addPoint(-88,67);
    } else if (shape==shape_star) {
      shapepolygon.addPoint(0,-100);
      shapepolygon.addPoint(24,-24);
      shapepolygon.addPoint(100,-23);
      shapepolygon.addPoint(39,25);
      shapepolygon.addPoint(61,100);
      shapepolygon.addPoint(0,56);
      shapepolygon.addPoint(-61,100);
      shapepolygon.addPoint(-39,25);
      shapepolygon.addPoint(-100,-23);
      shapepolygon.addPoint(-24,-24);
    }
  }

  // ######################### SAVE / LOAD OPTIONS

  // Loads the options values from lawaconfig.dat
  private void loadOptions() {
    ObjectInputStream fin = null;
    try {
      fin = new ObjectInputStream(new FileInputStream("laWa/lawaconfig.dat"));
      begin=fin.readInt();
      playmode=fin.readInt();
      setShape(fin.readInt());
      showFortress=fin.readBoolean();
      showLoosers=fin.readBoolean();
      showVictims=fin.readBoolean();
      player1=(String)fin.readObject();
      player2=(String)fin.readObject();;
      backgroundimage=(String)fin.readObject();
      player1color=(Color)fin.readObject();
      player1movecolor=(Color)fin.readObject();
      player2color=(Color)fin.readObject();
      player2movecolor=(Color)fin.readObject();
    } catch (EOFException e) {
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
    } finally {
      try {
        if (fin != null) {fin.close();}
      } catch (IOException e) {
      }
    }
  }

  // Saves the options values to lawaconfig.dat
  public void saveOptions() {
    ObjectOutputStream fin = null;
    try {
      fin = new ObjectOutputStream(new FileOutputStream("laWa/lawaconfig.dat"));
      fin.writeInt(begin);
      fin.writeInt(playmode);
      fin.writeInt(shape);
      fin.writeBoolean(showFortress);
      fin.writeBoolean(showLoosers);
      fin.writeBoolean(showVictims);
      fin.writeObject(player1);
      fin.writeObject(player2);
      fin.writeObject(backgroundimage);
      fin.writeObject(player1color);
      fin.writeObject(player1movecolor);
      fin.writeObject(player2color);
      fin.writeObject(player2movecolor);
    } catch (EOFException e) {
    } catch (IOException e) {
    } finally {
      try {
        if (fin != null) {fin.close();}
      } catch (IOException e) {
      }
    }
  }
}

// ######################### END OF FILE
